package at.connectme.templating.webservice;

import at.connectme.templating.service.TemplatingService;
import kiwi.core.qualifiers.transaction.Transactional;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import java.net.URLDecoder;

/**
 * User: Thomas Kurz
 * Date: 23.01.12
 * Time: 11:28
 */
@ApplicationScoped
@Transactional
@Path("/cmf/service/templating")
public class TemplatingWebService {

	@Inject
	TemplatingService templatingService;

	@GET
    @Path("/resource")
	public Response process(@QueryParam("uri") String uri, @QueryParam("template") String template) {
		try {
			return Response.ok().entity(templatingService.process(URLDecoder.decode(uri,"utf-8"), URLDecoder.decode(template, "utf-8"))).build();
		} catch (Exception e) {
			e.printStackTrace();
			return Response.serverError().entity(e.getMessage()).build();
		}
	}
}
